package com.retail.global.config;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.MD5;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 加密方式配置(加密方式)
 *
 * @author administrator
 * @date 2022 - 10 - 10 23:45:13
 */
@Configuration
public class PasswordEncoderConfig {

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new PasswordEncoder() {
            @Override
            public String encode(CharSequence rawPassword) {
                return MD5.create().digestHex(rawPassword + "");
            }

            @Override
            public boolean matches(CharSequence rawPassword, String encodedPassword) {
                return ObjectUtil.equal(MD5.create().digestHex(rawPassword + ""), encodedPassword);
            }
        };
    }
}
